const service = require("../service/article");
// 查找文章·
const articlecha = async (ctx) => {
  const res = await service.articlecha(ctx.request.body);
  if (res.length > 0) {
    ctx.body = {
      code: 200,
      message: "查询成功",
      data: res,
    };
  } else {
    ctx.body = {
      code: 403,
      message: "查询失败",
    };
  }
};
// - 医生登录后查看自己的文章  
const doctorarticle = async (ctx) => {
  const res = await service.doctorarticle(ctx.request.body);
  if (res.length > 0) {
    ctx.body = {
      code: 200,
      message: "查询成功",
      data: res,
    };
  } else {
    ctx.body = {
      code: 403,
      message: "查询失败",
    };
  }
};
//  医生登录后新增自己的文章
const doctoraddarticle = async (ctx) => {
  const res = await service.doctoraddarticle(ctx.request.body);// 新增文章
    const ress = await service.doctorarticle(ctx.request.body);
    console.log(ress,'ress')
     if(res.affectedRows > 0){
         ctx.body = {
             code: 200,
             message: "新增成功",
         };
     }else{
         ctx.body = {
             code: 403,
             message: "新增失败",
         };
     }
};
// 删除文章 
const doctordeletearticle= async (ctx) => {
  const res = await service.doctordeletearticle(ctx.request.body);
  if (res.affectedRows > 0) {
    ctx.body = {
      code: 200,
      message: "删除成功",
    };
  } else {
    ctx.body = {
      code: 403,
      message: "删除失败",
    };
  }
};  
module.exports = { articlecha ,doctorarticle,doctoraddarticle,doctordeletearticle};
